import java.util.Arrays;

class WashMachine {
    //属性 、 字段 、成员变量：这些成员变量是定义在方法外部 类的内部的
    public String brand; // 品牌
    public String type; // 型号
    public double weight; // 重量
    public double length; // 长
    public double width; // 宽
    public double height; // 高
    public String color; // 颜色

    //成员方法 -> 行为
    public void washClothes(){ // 洗衣服
        System.out.println("洗衣功能");
    }

    public void dryClothes(){ // 脱水
        System.out.println("脱水功能");
    }
    public void setTime(){ // 定时
        System.out.println("定时功能");
    }
}

class Student {
    public String name;
    public double score;
    public int age;

    public void DoClass(){}
    public void DoHomework(){}
    public void Exam(){}
}

class Dog {
    public String name;
    public String color;
    public int age;

    //-> 行为
    public void barks() {
        System.out.println(name + ": 旺旺旺~~~");
    }
    public void wag() {
        System.out.println(name + ": 摇尾巴~~~");
    }
}
class Date {
    public int year;
    public int month;
    public int day;

    public Date(int year,int month,int day) {
        this.year = year;
        this.month = month;
        this.day = day;
        System.out.println("Date(int,int,int)方法被调用了");
    }
    public Date() {
        System.out.println("Date()方法被调用了");
    }
    public void setDay(int year,int month,int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public void printDate() {
        System.out.println(this.year+"/"+this.month+"/"+this.day);
    }
}
public class Test {
    public static void main(String[] args) {
        Date d1 = new Date();
        d1.printDate();
        d1.setDay(2025,2,21);
        d1.printDate();

        Date d2 = new Date(2025,2,20);
        d1.printDate();
    }
    public static void main7(String[] args) {
        int[][] arr = {
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12}
        };

        for(int row = 0; row<arr.length; ++row) {
            for(int col = 0; col < arr[row].length; ++col) {
                System.out.printf("%d ",arr[row][col]);
            }
            System.out.println();
        }

        Dog dog1 = new Dog();
        dog1.name = "阿黄";
        dog1.age = 2;
        dog1.color = "黄色";
        System.out.println("年龄："+dog1.age);
        System.out.println("姓名："+dog1.name);
        System.out.println("颜色："+dog1.color);
        dog1.barks();
        dog1.wag();

        Date d1 = new Date();
        d1.setDay(2025,2,21);
        d1.printDate();
    }
    public static void main6(String[] args) {
        int[] array = new int[]{9,5,2,4};
//        Arrays.sort(array);
        bubbleSort(array);
        System.out.println("array: " + Arrays.toString(array));

        reverse(array);
        System.out.println("arrary: " + Arrays.toString(array));
    }

    public static void reverse(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
            left++;
            right--;
        }
    }

    public static void bubbleSort(int[] arr) {
        for(int i =0; i<arr.length; ++i) {
            for(int j =1; j < arr.length; ++j) {
                if(arr[j-1] > arr[j]) {
                    int tmp = arr[j-1];
                    arr[j-1] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
    }
    public static void main5(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        System.out.println(avg(arr));

        System.out.println(find(arr,4));

        System.out.println(binarySearch(arr,4));
    }
    public static int binarySearch(int[] arr,int targer) {
        int left = 0;
        int right = arr.length - 1;
        while(left <= right) {
            int mid = left + (right - left) / 2;
            if(mid < targer) {
                left = mid + 1;
            } else if(mid > targer) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static int find(int[] arr,int target) {
        for(int i =0; i<arr.length; ++i) {
            if(arr[i] == target) {
                return i;
            }
        }
        return -1;
    }
    public static double avg(int[] arr) {
        int sum = 0;
        for(int e : arr) {
            sum += e;
        }
        return (double)sum / (double)arr.length;
    }
    public static void func3() {
        int[] arr = {1,2,3,4,5,6};
        int[] newArr = arr;
        newArr[0] = 10;
        System.out.println("newArr:" + Arrays.toString(arr));

        arr[0] = 1;
        newArr = Arrays.copyOf(arr,arr.length);

        arr[0] = 10;
        System.out.println("arr: " + Arrays.toString(arr));
        System.out.println("newArr: " + Arrays.toString(newArr));

        // Arrays.copyOfRange(arr,2,4); [)
        int[] newArr2 = Arrays.copyOfRange(arr,2,4);
        System.out.println("newArr2: " + Arrays.toString(newArr2));

    }
    public static void main4(String[] args) {
//        int[] array = {1,2,3,4,5,6};
//        String newArr = Arrays.toString(array);
//        System.out.println(newArr);

        func3();
    }
    public static int[] fib(int n) {
        if(n <= 0) {
            return null;
        }

        int[] array = new int[n];
        array[0] = array[1] = 1;
        for(int i =2; i<array.length; ++i) {
            array[i] = array[i-1] + array[i-2];
        }
        return array;
    }
    public static void main3(String[] args) {
        int[] array = fib(10);
        for(int e : array) {
            System.out.print(e + " ");
        }
    }
    public static void main2(String[] args) {
        int num = 0;
        func(num);
        System.out.println("num="+num);
    }

    public static void func(int x) {
        x = 10;
        System.out.println("x="+x);
    }
    public static void main1(String[] args) {
/*        int[] array1 = new int[10];
        double[] array2 = new double[5];
        String[] array3 = new String[3];

        int[] array4 = {1,2,3,4};
        System.out.println(array4[0]);

        array4[0] = 99;
        System.out.println(array4[0]);

        System.out.println("数组的长度是"+ array4.length);

        for(var e : array1) {
            System.out.println(e);
        }

        for(int e : array1) {
            System.out.println(e);
        }*/

//        int[] array = new int[]{10,20,30,40,50};
//
//        for(int e : array) {
//            System.out.print(e + " ");
//        }
//        System.out.println();
//        array[0] = 100;
//        for(int e : array) {
//            System.out.print(e + " ");
//        }
//        System.out.println();
//        System.out.println(array.length);


        func1();
    }
    public static void func1() {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;

        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;

        array1 = array2;
        for(int e : array1) {
            System.out.println(e);
        }
        array1[2] = 300;
        array1[3] = 400;
        array1[4] = 500;

        for(int e : array2) {
            System.out.println(e);
        }
    }
}
